package dao

import (
	"gitee.com/lv_baobao/gcore/dbUtils"
	"gitee.com/lv_baobao/gcore/helper"
	"gitee.com/lv_baobao/gcore/testing/models"
)

type DeviceModelDao struct {
	*dbUtils.BaseDao
}

func NewDeviceModelDao() *DeviceModelDao {
	return &DeviceModelDao{
		BaseDao: &dbUtils.BaseDao{
			TableName: "DeviceModel",
		},
	}
}

func (this *DeviceModelDao) SearchPageList(pageIndex int, pageSize int, manufactorId int) *helper.QueryResult {
	var res = new(helper.QueryResult)
	var list = make([]models.DeviceModel, 0)
	return this.Queryable().OrderByDesc("ModelId").WhereIf("and manufactorId=?", manufactorId, manufactorId > 0).Page(pageIndex, pageSize, &list)
	return res
}

func (this *DeviceModelDao) Delete(id int64) bool {
	this.Queryable().Where("and modelId=?", id).Delete()
	return true
}

func (this *DeviceModelDao) GetAll() []models.DeviceModel {
	deviceModels := make([]models.DeviceModel, 0)
	this.Queryable().List(&deviceModels)
	return deviceModels
}
